const gulp = require('gulp');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const webpack = require('webpack-stream');
const named = require('vinyl-named');
const watch = require('gulp-watch');
var sass = require('gulp-sass');

sass.compiler = require('node-sass');
let transforms = [
    {
        transform: 'babelify',
        options: { presets: ['@babel/env'] }
    }
];

//任务
function scssTask() {
    return gulp.src('sass/**/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('css/'))
}
function scripts() {
    return gulp.src('scripts/**/*.js')
        .pipe(babel({ presets: ['@babel/env']/* , plugins: ['@babel/transform-runtime'] */ }))
        //.pipe(uglify())
        .pipe(named())
        //.pipe(webpack())
        .pipe(gulp.dest('js/'))

}
gulp.watch(['scripts/**/*.js'], scripts);
gulp.watch(['sass/**/*.scss'], scssTask);
exports.default = function () {
    scssTask();
    scripts();
}
